package com.tmall.wireless.virtualviewdemo.utils.imageloader.core.decode;

import com.tmall.wireless.virtualviewdemo.utils.imageloader.core.DisplayImageOptions;
import com.tmall.wireless.virtualviewdemo.utils.imageloader.core.assist.ImageScaleType;
import com.tmall.wireless.virtualviewdemo.utils.imageloader.core.assist.ImageSize;
import com.tmall.wireless.virtualviewdemo.utils.imageloader.core.assist.ViewScaleType;
import com.tmall.wireless.virtualviewdemo.utils.imageloader.core.download.ImageDownloader;
import ohos.media.image.ImageSource;

public class ImageDecodingInfo {
    private final String imageKey;
    private final String imageUri;
    private final String originalImageUri;
    private final ImageSize targetSize;

    private final ImageScaleType imageScaleType;
    private final ViewScaleType viewScaleType;

    private final ImageDownloader downloader;
    private final Object extraForDownloader;

    private final boolean considerExifParams;
    private final ImageSource.DecodingOptions decodingOptions;

    public ImageDecodingInfo(String imageKey, String imageUri, String originalImageUri, ImageSize targetSize, ViewScaleType viewScaleType,
                             ImageDownloader downloader, DisplayImageOptions displayOptions) {
        this.imageKey = imageKey;
        this.imageUri = imageUri;
        this.originalImageUri = originalImageUri;
        this.targetSize = targetSize;
        this.imageScaleType = displayOptions.getImageScaleType();
        this.viewScaleType = viewScaleType;

        this.downloader = downloader;
        this.extraForDownloader = displayOptions.getExtraForDownloader();

        considerExifParams = displayOptions.isConsiderExifParams();
        decodingOptions = new ImageSource.DecodingOptions();
        copyOptions(displayOptions.getDecodingOptions(), decodingOptions);
    }

    private void copyOptions(ImageSource.DecodingOptions srcOptions, ImageSource.DecodingOptions destOptions) {

        destOptions.allocator = srcOptions.allocator;
        destOptions.allowPartialImage = srcOptions.allowPartialImage;
        destOptions.desiredColorSpace = srcOptions.desiredColorSpace;
        destOptions.desiredPixelFormat = srcOptions.desiredPixelFormat;
        destOptions.desiredRegion = srcOptions.desiredRegion;
        destOptions.desiredSize = srcOptions.desiredSize;
        destOptions.editable = srcOptions.editable;
        destOptions.fitDensity = srcOptions.fitDensity;
        destOptions.rotateDegrees = srcOptions.rotateDegrees;
        destOptions.sampleSize = srcOptions.sampleSize;


    }


    public String getImageKey() {
        return imageKey;
    }

    /**
     * getImageUri
     * @return Image URI for decoding (usually image from disk cache)
     */
    public String getImageUri() {
        return imageUri;
    }

    /**
     * getOriginalImageUri
     * @return The original image URI which was passed to ImageLoader
     */
    public String getOriginalImageUri() {
        return originalImageUri;
    }

    /**
     * getTargetSize
     * @return Target size for image. Decoded bitmap should close to this size according to {@linkplain ImageScaleType
     * image scale type} and {@linkplain ViewScaleType view scale type}.
     */
    public ImageSize getTargetSize() {
        return targetSize;
    }

    /**
     * getImageScaleType
     * @return {@linkplain ImageScaleType Scale type for image sampling and scaling}. This parameter affects result size
     * of decoded bitmap.
     */
    public ImageScaleType getImageScaleType() {
        return imageScaleType;
    }

    /**
     * getViewScaleType
     * @return {@linkplain ViewScaleType View scale type}. This parameter affects result size of decoded bitmap.
     */
    public ViewScaleType getViewScaleType() {
        return viewScaleType;
    }

    /**
     * getDownloader
     * @return Downloader for image loading
     */
    public ImageDownloader getDownloader() {
        return downloader;
    }

    /**
     * getExtraForDownloader
     * @return Auxiliary object for downloader
     */
    public Object getExtraForDownloader() {
        return extraForDownloader;
    }

    /**
     * shouldConsiderExifParams
     * @return <b>true</b> - if EXIF params of image should be considered; <b>false</b> - otherwise
     */
    public boolean shouldConsiderExifParams() {
        return considerExifParams;
    }

    /**
     * getDecodingOptions
     * @return Decoding options
     */
    public ImageSource.DecodingOptions getDecodingOptions() {
        return decodingOptions;
    }
}
